package com.major.crowd.controller;

import com.major.crowd.service.api.ProjectService;
import com.major.crowd.util.ResultEntity;
import com.major.crowd.vo.DetailProjectVO;
import com.major.crowd.vo.PortalTypeVO;
import com.major.crowd.vo.ProjectVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ProjectProviderController {

    @Autowired
    private ProjectService projectService;

    Logger logger = LoggerFactory.getLogger(ProjectProviderController.class);

    /**
     * 控制层：查询项目详情
     * @param projectId
     * @return
     */
    @RequestMapping("/get/detail/project/remote/{projectId}")
    public ResultEntity<DetailProjectVO> getDetailProjectVORemote(@PathVariable("projectId") Integer projectId){
        try {
            DetailProjectVO detailProjectVO = projectService.getDetailProjectVO(projectId);
            return ResultEntity.successWithData(detailProjectVO);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }


    /**
     * 查到所有分类和项目的信息
     * @return
     */
    @RequestMapping("/get/portal/type/project/data/remote")
    public ResultEntity<List<PortalTypeVO>> getPortalTypeProjectDataRemote(){
        try {

            List<PortalTypeVO> portalTypeVOList = projectService.getPortalTypeVO();
            return ResultEntity.successWithData(portalTypeVOList);

        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }

    /**
     * 保存项目信息
     * @param projectVO
     * @param memberId
     * @return
     */
    @RequestMapping("save/project/vo/remote")
    public ResultEntity<String> saveProjectVORemote(@RequestBody ProjectVO projectVO, @RequestParam("memberId") Integer memberId){

        try {
            logger.info(String.valueOf(projectService));
            logger.info("11111111111111111111111111111111111111111111111111");
            projectService.saveProject(projectVO,memberId);
            return ResultEntity.successWithoutData();
        } catch (Exception e) {
            e.printStackTrace();
            return ResultEntity.failed(e.getMessage());
        }
    }
}
